package RMI.client.PromoManager.GUI;
import RMI.server.interfaces.Comunication;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import javax.swing.ImageIcon;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;





/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class PromoManagerGUI extends javax.swing.JFrame {
	private JTextField vlr_1;
	private JLabel Calculadora;
	private JLabel lb_resultado;
	private JLabel jLabel2;
	private JButton bt_calcular;
	private JLabel jLabel1;
	private JTextField vlr_2;

	private Comunication objRemoto=null;
	
	public PromoManagerGUI() {
		super();
		initGUI();
		int port = 1099;
        try {
            Registry registry = LocateRegistry.getRegistry("localhost", port);
            objRemoto = (Comunication) registry.lookup("clienteCalculadora");
            
        } catch (NotBoundException e) {
            System.out.println("Aplica��o n�o encontrada: " + e.getMessage());
        } catch (RemoteException e) {
            System.out.println(e);
        }
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				vlr_1 = new JTextField();
				getContentPane().add(vlr_1);
				vlr_1.setBounds(86, 62, 59, 21);
			}
			{
				vlr_2 = new JTextField();
				getContentPane().add(vlr_2);
				vlr_2.setBounds(176, 62, 59, 21);
			}
			{
				Calculadora = new JLabel();
				getContentPane().add(Calculadora);
				Calculadora.setText("Calculadora");
				Calculadora.setBounds(5, 65, 75, 14);
			}
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("+");
				jLabel1.setBounds(157, 65, 15, 14);
			}
			{
				bt_calcular = new JButton();
				getContentPane().add(bt_calcular);
				bt_calcular.setText("Calcular");
				bt_calcular.setBounds(253, 55, 142, 44);
				bt_calcular.setIcon(new ImageIcon(getClass().getClassLoader().getResource("br/com/RMI/client/PromoManager/images/clientes.gif")));
				bt_calcular.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						try {
							CalcularActionPerformed(evt);
						} catch (RemoteException e) {
							e.printStackTrace();
						} 
					}
				});
			}
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setText("RESULTADO:");
				jLabel2.setBounds(5, 117, 83, 14);
			}
			{
				lb_resultado = new JLabel();
				getContentPane().add(lb_resultado);
				lb_resultado.setBounds(94, 117, 55, 14);
			}
			pack();
			this.setSize(423, 300);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				PromoManagerGUI inst = new PromoManagerGUI();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	private void CalcularActionPerformed(ActionEvent evt) throws RemoteException {
		int um = Integer.parseInt(vlr_1.getText());
		int dois = Integer.parseInt(vlr_2.getText());
		lb_resultado.setText(objRemoto.soma(um,dois));
		
	}

}
